Remove["Global`*"]
xv={12.8,17.6, 21.5,24.0, 27.1, 30.2, 32.5};
fv={2.4,0.6, 4.0, 6.0, 4.7, 1.8,-0.6};
data=Transpose[{xv,fv}];

n=Length[xv];
{dfl,dfr}={0,0};

deg=3; (* s(x) spline-funktion av grad deg *)
k = (fv[[1]]-4.2)/(xv[[1]]-7.4);
m = 4.2-k*7.4;

l[x_] = k*x + m;
s1[x_]=Sum[a[i](x-xv[[n-6]])^i,{i,0,deg}];
s2[x_]=Sum[b[i](x-xv[[n-5]])^i,{i,0,deg}];
s3[x_]=Sum[c[i](x-xv[[n-4]])^i,{i,0,deg}];
s4[x_]=Sum[d[i](x-xv[[n-3]])^i,{i,0,deg}];
s5[x_]=Sum[e[i](x-xv[[n-2]])^i,{i,0,deg}];
s6[x_]=Sum[f[i](x-xv[[n-1]])^i,{i,0,deg}];


const=Join[
Table[a[i],{i,0,deg}],Table[b[i],{i,0,deg}],
Table[c[i],{i,0,deg}],Table[d[i],{i,0,deg}],
Table[e[i],{i,0,deg}],Table[f[i],{i,0,deg}]];

sol=Solve[{
s1[xv[[1]]] == fv[[1]],
s1[xv[[2]]]== s2[xv[[2]]] == fv[[2]],
s2[xv[[3]]] == s3[xv[[3]]] ==  fv[[3]],
s3[xv[[4]]] == s4[xv[[4]]] ==  fv[[4]],
s4[xv[[5]]] == s5[xv[[5]]] ==  fv[[5]],
s5[xv[[6]]] == s6[xv[[6]]] ==  fv[[6]],
s6[xv[[7]]] == fv[[7]],

s1'[xv[[2]]] == s2'[xv[[2]]],
s2'[xv[[3]]] == s3'[xv[[3]]],
s3'[xv[[4]]] == s4'[xv[[4]]],
s4'[xv[[5]]] == s5'[xv[[5]]],
s5'[xv[[6]]] == s6'[xv[[6]]],

s1''[xv[[2]]]==s2''[xv[[2]]],
s2''[xv[[3]]]==s3''[xv[[3]]],
s3''[xv[[4]]]==s4''[xv[[4]]],
s4''[xv[[5]]]==s5''[xv[[5]]],
s5''[xv[[6]]]==s6''[xv[[6]]],

s1'[xv[[1]]] == k,
s6''[xv[[7]]] == 0
},const
];

s[x_] = l[x]UnitBox[((x-7.4)/(xv[[1]]-7.4))-(1/2)]+
  s1[x]UnitBox[((x-xv[[1]])/(xv[[2]]-xv[[1]]))-(1/2)] + s2[x]UnitBox[((x-xv[[2]])/(xv[[3]]-xv[[2]]))-(1/2)] + 
s3[x]UnitBox[((x-xv[[3]])/(xv[[4]]-xv[[3]]))-(1/2)] + s4[x]UnitBox[((x-xv[[4]])/(xv[[5]]-xv[[4]]))-(1/2)] +
s5[x]UnitBox[((x-xv[[5]])/(xv[[6]]-xv[[5]]))-(1/2)] +
s6[x]UnitBox[((x-xv[[6]])/(xv[[7]]-xv[[6]]))-(1/2)];
pl = Plot[s[x]/.sol[[1]], {x, 7.4, xv[[7]]}];
lp=ListPlot[data,PlotStyle->{Red,PointSize[Large]}];
Show[{pl, lp}]

(*2.6*)
Print["*******"]
Print["* 2.6 *"]
Print["*******"]
yn=Table[s[i],{i,7.4,32.5}]/.sol[[1]];
xn=Table[i,{i,7.4,32.5}];
data2=Transpose[Append[{xn},yn]];
lp2=ListPlot[data2,PlotStyle->{Red,PointSize[Large]}];
Show[lp2]

Print["Estimated length: ",(∑_(i=1)^(Length[xn]-1))(Sqrt[(xn[[i+1]]-xn[[i]])^2+(yn[[i+1]]-yn[[i]])^2])]